package com.will.txj.wy.server.controller;

import com.will.txj.common.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: wen-yi;
 * @date: 2021/12/7 15:40;
 * @Description:
 * PreAuthorize 资源服务器失去了对权限的控制权
 */
@Slf4j
@Api(tags = "应用控制层")
@RestController
@RequestMapping("app")
public class APPController {
    @ApiOperation("登录信息")
    @PostMapping
    public R hello(HttpServletRequest request){
        log.info("请求登录信息 -> host: {}, port: {}",request.getRemoteHost(),request.getRemotePort());
        return R.ok();
    }

    @ApiOperation("角色验证")
    @GetMapping("role")
    public R role(HttpServletRequest request){
        log.info("请求角色验证 -> host: {}, port: {}",request.getRemoteHost(),request.getRemotePort());
        return R.ok("你的角色验证通过");
    }

    @ApiOperation("权限验证")
    @GetMapping("permission")
    public R permission(HttpServletRequest request){
        log.info("请求权限验证 -> host: {}, port: {}",request.getRemoteHost(),request.getRemotePort());
        return R.ok("你的权限验证通过");
    }
}
